package com.imooc.springboot.dubbo.nilinili.consumer.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.imooc.springboot.dubbo.nilinili.entity.bean.PageBean;
import com.imooc.springboot.dubbo.nilinili.entity.dto.PhotographerDTO;
import com.imooc.springboot.dubbo.nilinili.entity.dto.PhotographerWorkDTO;
import com.imooc.springboot.dubbo.nilinili.res.CodeEnum;
import com.imooc.springboot.dubbo.nilinili.res.ResultFactory;
import com.imooc.springboot.dubbo.nilinili.service.CollectionService;
import com.imooc.springboot.dubbo.nilinili.service.PhotoService;
import com.imooc.springboot.dubbo.nilinili.service.PhotographerService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/photographer")
public class PhotographerController {
    @Reference
    private PhotographerService photographerService;

    @Reference
    private PhotoService photoService;

    @Reference
    private CollectionService collectionService;

    @GetMapping("/getAllUserInfo")
    public String getAllUserInfo(@RequestParam("pageNum")  int pageNum){
        PageBean<PhotographerDTO> photographerDTOS=photographerService.getAllUserInfo(pageNum);
        // 遍历修改用户数据
        for (PhotographerDTO photographerDTO : photographerDTOS.getList()) {
            photoService.getAllPhotoCounts(photographerDTO.getUserId());
            photoService.getAllPhotoApprovalCounts(photographerDTO.getUserId());
            collectionService.countCollection(photographerDTO.getUserId());
        }
        PageBean<PhotographerDTO> newPhotographerDTOS=photographerService.getAllUserInfo(pageNum);
        return ResultFactory.createResult(CodeEnum.SUCCESS,"成功获取摄影师列表",newPhotographerDTOS);
    }

    @GetMapping("/getUserWorks/{id}")
    public String getUserWorksByUserId(@PathVariable("id") Integer user_id){
        List<PhotographerWorkDTO>photographerWorkDTOS = photographerService.getUserWorks(user_id);
        return ResultFactory.createResult(CodeEnum.SUCCESS, "成功获取摄影师作品", photographerWorkDTOS);
    }
}
